package demo.spring.batis.contillection;

import demo.spring.batis.model.UserModel;
import demo.spring.batis.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by Qian on 2017/3/2.
 */
@RestController
@RequestMapping(value = "/demo")
public class DemoCollection {
 @Autowired
 private DemoService demoservice;
    @RequestMapping("/heihei")
    @Scheduled(fixedRate=2000)
    public void heihei(){
    System.out.println("我爱你");
    }

 @RequestMapping("/user")
 public UserModel add(){
UserModel userModel=new UserModel("小钱",17,"6","@6");
  demoservice.add(userModel);
  System.out.println("添加数据");
  return userModel;
 }

 @RequestMapping("/delete")
 public List<UserModel> delete(String name){
demoservice.delete(name);
  System.out.println("删除数据");
  return getAll();
 }

 @RequestMapping("/update")
 public List<UserModel> update(){
UserModel userModel=new UserModel("小小",20,"10","@10");
  demoservice.update(userModel);
  System.out.println("修改数据");
  return getAll();
 }

 @RequestMapping("/getAll")
 public List<UserModel> getAll(){
 List<UserModel> user=demoservice.getAll();
  System.out.println("查询所有数据");
  return  user;
 }
 @RequestMapping("/select")
 public List<UserModel> select() {
     String name="小小";
      List<UserModel> list = demoservice.select(name);
return list;
 }
}
